package com.itheima.反射.反射案例;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.util.Properties;

public class Test {
    public static void main(String[] args) throws Exception {
        //加载配置文件
        Properties prop = new Properties();

        InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("proper.properties");
        BufferedReader br = new BufferedReader(new InputStreamReader(is,"GBK"));
        prop.load(br);

        //获取字节码文件对象
        Class aClass = Class.forName(prop.getProperty("className"));
        //通过反射获取method对象
        Method method = aClass.getDeclaredMethod(prop.getProperty("methodName"));
        //暴力反射
        method.setAccessible(true);
        //创建类的对象
        Object obj = aClass.newInstance();
        //通过invoke进行调用
        method.invoke(obj);
    }
}
